package cn.hqc.basic.utils;


import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult {

    private Integer code;

    private Boolean success;

    private String msg;

    private Object resultObj;

    private static AjaxResult me(){
        return new AjaxResult();
    }

    public static AjaxResult fail(BussinessException e){
        return AjaxResult.me().setCode(e.getCode())
                .setSuccess(false).setMsg(e.getMessage());
    }

    public static AjaxResult fail(String msg){
        return AjaxResult.me().setCode(GlobalErrorCode.FAIL.getCode())
                .setSuccess(false).setMsg(msg);
    }

    public static AjaxResult fail(){
        return AjaxResult.me().setCode(GlobalErrorCode.FAIL.getCode())
                .setSuccess(false).setMsg(GlobalErrorCode.FAIL.getMessage());
    }

    public static AjaxResult success(Object resultObj){
        return AjaxResult.me().setCode(GlobalErrorCode.SUCCESS.getCode())
                .setSuccess(true).setMsg(GlobalErrorCode.SUCCESS.getMessage()).setResultObj(resultObj);
    }

    public static AjaxResult success(){
        return AjaxResult.me().setCode(GlobalErrorCode.SUCCESS.getCode())
                .setSuccess(true).setMsg(GlobalErrorCode.SUCCESS.getMessage());
    }

    public Boolean getSuccess() {
        return success;
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Object getResultObj() {
        return resultObj;
    }

    public AjaxResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public AjaxResult setResultObj(Object resultObj){
        this.resultObj = resultObj;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public AjaxResult setCode(Integer code){
        this.code = code;
        return this;
    }
}
